#include <cstdio>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

void
test_perspective_proj() {
	float neardist = 0.1f, fardist = 100.0f;
	glm::vec4 nearpoint(0.0f, 0.0f, -neardist, 1.0f);
	glm::vec4 farpoint(0.0f, 0.0f, -fardist, 1.0f);
	glm::mat4 persmat = glm::perspective(glm::radians(45.0f), 4.0f/3.0f, neardist, fardist);
    
    glm::vec4 nearpoint_clip = persmat * nearpoint;
    glm::vec4 farpoint_clip = persmat * farpoint;
    nearpoint_clip /= nearpoint_clip.w;
    farpoint_clip /= farpoint_clip.w;

    glm::vec3 ndc_near(nearpoint_clip);
    glm::vec3 ndc_far(farpoint_clip);
    printf("one point in near plane:<%f, %f, %f>\n", ndc_near.x, ndc_near.y, ndc_near.z);
    printf("one point in far plane:<%f, %f, %f>\n", ndc_far.x, ndc_far.y, ndc_far.z);
/**
输出如下：
one point in near plane:<0.000000, 0.000000, -1.000000>
one point in far plane:<0.000000, 0.000000, 1.000000>
 */
}

void
test_orthographic_proj() {
	float neardist = -100.0f, fardist = 100.0f;
	glm::vec4 nearpoint(0.0f, 0.0f, -neardist, 1.0f);
	glm::vec4 farpoint(0.0f, 0.0f, -fardist, 1.0f);
	glm::mat4 persmat = glm::ortho(-4.0f, 4.0f, -3.0f, 3.0f, neardist, fardist);
    
    glm::vec4 nearpoint_clip = persmat * nearpoint;
    glm::vec4 farpoint_clip = persmat * farpoint;
    nearpoint_clip /= nearpoint_clip.w;
    farpoint_clip /= farpoint_clip.w;

    glm::vec3 ndc_near(nearpoint_clip);
    glm::vec3 ndc_far(farpoint_clip);
    printf("one point in near plane:<%f, %f, %f>\n", ndc_near.x, ndc_near.y, ndc_near.z);
    printf("one point in far plane:<%f, %f, %f>\n", ndc_far.x, ndc_far.y, ndc_far.z);
/**
输出如下：
one point in near plane:<0.000000, 0.000000, -1.000000>
one point in far plane:<0.000000, 0.000000, 1.000000>
 */
}

int 
main() {
	test_perspective_proj();
	printf("\n");
	test_orthographic_proj();
}